package com.gopay.bis.web.controller.ebank;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.bis.domain.order.OrderInfo;
import com.gopay.common.Result;
import com.gopay.common.constants.bank.BankConstants;
import com.gopay.common.constants.bank.BisBankBusinessProd;
import com.gopay.common.constants.bank.BisBankInterfaceChannel;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.abc.ebank.AbcB2cMessage;
@Controller
@Scope("prototype")
public class AbcB2cServerRes  extends BankResBase {
	
	 private static Log logger = LogFactory.getLog(AbcB2cServerRes.class);
	
	 @RequestMapping(value = "/AbcB2cServerRes")
	 protected ModelAndView execute(HttpServletRequest request,HttpServletResponse response) {
	        logger.error("--------------- AbcB2cServerRes bankback ---------------");
	        return super.execute(request, response);
	        
	 }
	 
	 
	protected BaseMessage buildMessage(HttpServletRequest request) {
		AbcB2cMessage message = new AbcB2cMessage();
		message.setMsg(request.getParameter("MSG"));
		message.setBank(BankConstants.BANK_LOGO_ABC);
        //银行业务产品00个人网银支付
        message.setBankBusProd(BisBankBusinessProd._00);
        // 银行接口通道信息 00: 直连
        message.setBankIntrChann(BisBankInterfaceChannel._00);
		return message;
	}
	
	@Override
	protected OrderInfo buildOrderInfo(HttpServletRequest request, Result result) {
		 OrderInfo orderInfo = new OrderInfo();
		    AbcB2cMessage b2cMessage = (AbcB2cMessage)result.getModel("res");
		    if(b2cMessage!=null)
		    {
		    	if(b2cMessage.isSuccess()){
			        orderInfo.setOrderId(b2cMessage.getResOrderNo());
			        orderInfo.setAmt(b2cMessage.getResAmount());
			        orderInfo.setNotifyNum("1");
			        orderInfo.setPayStatus("00");
			        orderInfo.setRetCode("00");
			        orderInfo.setRetMsg("");
		    	}else{
		    		orderInfo.setOrderId(b2cMessage.getResOrderNo());
			         orderInfo.setAmt(b2cMessage.getResAmount());
			         orderInfo.setNotifyNum("1");
			         orderInfo.setPayStatus("01");
			         orderInfo.setRetCode("01");
			         orderInfo.setRetMsg("");
		    	}
		    }
		    orderInfo.setBankName("abc");
	        orderInfo.setIsNotify(true);
	        return orderInfo;
	}


	@Override
	protected boolean checkParameters(HttpServletRequest request) {
		if(StringUtils.isEmpty(request.getParameter("MSG"))){
        	return false;
        }
	return true;
	}

}
